package untiring07.j2ee.basic.util.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class OracleDB {
	private static String DRV = "oracle.jdbc.driver.OracleDriver";
	private static String URL = "jdbc:oracle:thin:untiring07/untiring07@112.216.253.125:1521:xe";
	
	public static Connection openConn() {
		try {
			Class.forName(DRV);
			return DriverManager.getConnection(URL);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	public static Connection openCPConn(){
		try{
		Context initCtx = new InitialContext();
		Context	ctx =(Context)initCtx.lookup("java:comp/env");
		DataSource ds=(DataSource)ctx.lookup("jdbc/OracleDB");
		return ds.getConnection();
		}catch(Exception e){
		}
		return null;
	}
	public static void closeConn( 
		Connection c, PreparedStatement p, ResultSet r ) {
		if (r != null) try {r.close(); r = null;} catch (Exception e) {}
		if (p != null) try {p.close(); p = null;} catch (Exception e) {}
		if (c != null) try {c.close(); c = null;} catch (Exception e) {}
	}
	
}

